#!/bin/bash

# 查看各个文件中的字段数
# yzhaozilong v1.0
# 在使用里可以根据sort来排序,如./script.sh 目录 分隔符 | sort -n -t ":" -k 2  (-r 反向排序)

E_WRONGARGS=65

if [ ! -d "$1" ]
then
   echo "$1 is not directory!"
   exit $E_WRONGARGS
fi

temp=$2
if [ ${#temp} != 1 ]
then
   echo "second arg length don't with one"
   exit $E_WRONGARGS
fi

case "$2" in
[[:punct:]]  ) ;;
*            ) echo "second arg with punctuation symbol"; exit $E_WRONGARGS;;
esac

for file in $(find $1 -type f)
do
   string=`sed -n '1p' $file | awk 'BEGIN {FS="'$2'"} {print "column: "NF}'`
   echo "$file==>$string"
  
done
